<!--#Include File="Include.asp"--><%
'--------------------------------------
'Power By 方卡在线 @2010-2014 f02
'URL:http://www.fangka.net/
'EMail:admin@ifangka.com
'QQ:861118936
'版权所有 未经允许不得去除本版权信息
'--------------------------------------

Call CheckAdminType("0,1",UType)
Call CheckAdminLimit(ULimit,"o_Subject",0)

Dim Fk_Subject_Name,Fk_Subject_About,Fk_Subject_Pic,Fk_Subject_Template,Fk_Subject_Dir

Types=Clng(Request.QueryString("Type"))

Select Case Types
	Case 1
		Call SubjectList() '专题列表
	Case 2
		Call SubjectAddForm() '添加专题表单
	Case 3
		Call SubjectAddDo() '执行添加专题
	Case 4
		Call SubjectEditForm() '修改专题表单
	Case 5
		Call SubjectEditDo() '执行修改专题
	Case 6
		Call SubjectDelDo() '执行删除专题
	Case Else
		Call FKFun.ShowErr("未发现功能项！",1)
End Select

'==========================================
'函 数 名：SubjectList()
'作    用：专题列表
'==========================================
Sub SubjectList()
%>
		<div id="rightNav">
			<ul>
				<li><a href="Subject.asp?Type=2" target="dialog" width="500">添加专题</a></li>
			</ul>
		</div>
		<div id="searchLine" class="font_bold">
			专题管理
		</div>
		<table width="100%" bordercolor="#CCCCCC" border="1" cellspacing="0" cellpadding="0">
			<tr>
				<th align="center">ID</th>
				<th align="center">名称</th>
				<th align="center">模板</th>
				<th align="center">目录</th>
				<th align="center">操作</th>
			</tr>
<%
	Sqlstr="Select Fk_Subject_Id,Fk_Subject_Name,Fk_Subject_Template,Fk_Subject_Dir From [Fk_Subject] Order By Fk_Subject_Id Desc"
	Rs.Open Sqlstr,Conn,1,1
	If Not Rs.Eof Then
		i=1
		While Not Rs.Eof
			If Rs("Fk_Subject_Template")<>"" Then
				Fk_Subject_Template=Rs("Fk_Subject_Template")
			Else
				Fk_Subject_Template="默认模板"
			End If
%>
			<tr>
				<td height="20" align="center"><%=Rs("Fk_Subject_Id")%></td>
				<td align="center"><%=Rs("Fk_Subject_Name")%></td>
				<td align="center"><%=Fk_Subject_Template%></td>
				<td align="center"><%=SiteDir%>Subject/<%=Rs("Fk_Subject_Dir")%>/</td>
				<td align="center"><a href="Subject.asp?Type=4&Id=<%=Rs("Fk_Subject_Id")%>" target="dialog" width="500">修改</a> <a href="Subject.asp?Type=6&Id=<%=Rs("Fk_Subject_Id")%>" target="delete" confirmStr="您确认要删除“<%=Rs("Fk_Subject_Name")%>”？此操作不可逆！" refreshUrl="Subject.asp?Type=1" showStr="名称删除成功！">删除</a></td>
			</tr>
<%
			Rs.MoveNext
			i=i+1
		Wend
	Else
%>
			<tr>
				<td height="25" colspan="20" align="center">暂无记录</td>
			</tr>
<%
	End If
	Rs.Close
%>
			<tr>
				<td height="30" colspan="20">&nbsp;</td>
			</tr>
		</table>
		<div id="rightBottom">
		
		</div>
<%
End Sub

'==========================================
'函 数 名：SubjectAddForm()
'作    用：添加专题表单
'==========================================
Sub SubjectAddForm()
%>
<form id="SubjectAdd" name="SubjectAdd" method="post" target="ajax" action="Subject.asp?Type=3" showStr="新专题添加成功！" refreshUrl="Subject.asp?Type=1" boxClose="1">
<div id="title">添加新专题</div>
<div id="box">
	<table width="90%" border="1" bordercolor="#CCCCCC" align="center" cellpadding="0" cellspacing="0">
		<tr>
			<td width="24%" height="30" align="right">名称：</td>
			<td width="76%">&nbsp;<input name="Fk_Subject_Name" type="text" class="input" id="Fk_Subject_Name" /><span class="help" title="<p>专题名称，请输入1-50个字符（两个字符为一个汉字）。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">简介：</td>
			<td>&nbsp;<input name="Fk_Subject_About" type="text" class="input" id="Fk_Subject_About" /><span class="help" title="<p>对方站点的简介，可留空，请输入0-255个字符（1个汉字为2个字符）。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">图片：</td>
			<td>&nbsp;<input name="Fk_Subject_Pic" type="text" class="input" id="Fk_Subject_Pic" /> <input type="button" class="picList_btn btnUpload" name="btnLogo" id="btnLogo" value="上传LOGO" callback="2" inputId="Fk_Subject_Pic" fileAction="Upload.asp?immediate=3" /><span class="help" title="<p>专题图片，可留空，请输入0-255个字符，可以输入链接，也可以上传到空间。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">目录：</td>
			<td>&nbsp;<input name="Fk_Subject_Dir" type="text" class="input" id="Fk_Subject_Dir" /><span class="help" title="<p>专题目录。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">所属类型：</td>
			<td>&nbsp;<select name="Fk_Subject_Template" class="input" id="Fk_Subject_Template">
					<option value="">默认模板</option>
                </select><span class="help" title="<p>选择模板。</p>"></span>
			</td>
		</tr>
	</table>
</div>
<div id="bottom">
	<input type="submit" class="button" name="Enter" id="Enter" value="添 加" />
	<input type="button" onclick="dialogClose();" class="button" name="button" id="button" value="关 闭" />
</div>
</form>
<%
End Sub

'==============================
'函 数 名：SubjectAddDo
'作    用：执行添加专题
'==============================
Sub SubjectAddDo()
	Fk_Subject_Name=FKFun.HTMLEncode(Trim(Request.Form("Fk_Subject_Name")))
	Fk_Subject_About=FKFun.HTMLEncode(Trim(Request.Form("Fk_Subject_About")))
	Fk_Subject_Pic=FKFun.HTMLEncode(Trim(Request.Form("Fk_Subject_Pic")))
	Fk_Subject_Dir=Server.URLEncode(FKFun.HTMLEncode(Trim(Request.Form("Fk_Subject_Dir"))))
	Fk_Subject_Template=Trim(Request.Form("Fk_Subject_Template"))
	Call FKFun.JsonString(Fk_Subject_Name,1,50,0,"请输入专题名称！","专题名称不能大于255个字符！")
	Call FKFun.JsonString(Fk_Subject_About,1,255,2,"请输入专题介绍！","专题介绍不能大于255个字符！")
	Call FKFun.JsonString(Fk_Subject_Pic,1,255,2,"请输入专题图片！","专题图片不能大于255个字符！")
	Call FKFun.JsonString(Fk_Subject_Dir,1,255,2,"请输入专题目录！","专题目录不能大于255个字符！")
	Call FKFun.JsonString(Fk_Subject_Template,1,50,2,"请选择模板！","模板不能大于50个字符！")
	If IsNumeric(Fk_Subject_Dir) Then
		Call FKFun.JsonError("专题目录不能为纯数字！")
	End If
	Sqlstr="Select Fk_Subject_Id,Fk_Subject_Name,Fk_Subject_About,Fk_Subject_Pic,Fk_Subject_Dir,Fk_Subject_Template,Fk_Subject_ToHtml From [Fk_Subject] Where Fk_Subject_Name='"&Fk_Subject_Name&"'"
	If Fk_Subject_Dir<>"" Then
		Sqlstr=Sqlstr&" Or Fk_Subject_Dir='"&Fk_Subject_Dir&"'"
	End If
	Rs.Open Sqlstr,Conn,1,3
	If Rs.Eof Then
		Application.Lock()
		Rs.AddNew()
		Rs("Fk_Subject_Name")=Fk_Subject_Name
		Rs("Fk_Subject_About")=Fk_Subject_About
		Rs("Fk_Subject_Pic")=Fk_Subject_Pic
		Rs("Fk_Subject_Dir")=Fk_Subject_Dir
		Rs("Fk_Subject_Template")=Fk_Subject_Template
		Rs("Fk_Subject_ToHtml")=1
		Rs.Update()
		If Fk_Subject_Dir="" Then
			Rs.Close
			Sqlstr="Select Fk_Subject_Id,Fk_Subject_Dir From [Fk_Subject] Where Fk_Subject_Name='"&Fk_Subject_Name&"'"
			Rs.Open Sqlstr,Conn,1,3
			If Not Rs.Eof Then
				Rs("Fk_Subject_Dir")=Rs("Fk_Subject_Id")
				Rs.Update()
			End If
		End If
		Application.UnLock()
		Call FKFun.JsonSuccess()
	Else
		Rs.Close
		Call FKFun.JsonError("该专题已经存在！")
	End If
	Rs.Close
End Sub

'==========================================
'函 数 名：SubjectEditForm()
'作    用：修改专题表单
'==========================================
Sub SubjectEditForm()
	Id=Clng(Request.QueryString("Id"))
	Sqlstr="Select Fk_Subject_Name,Fk_Subject_About,Fk_Subject_Pic,Fk_Subject_Dir,Fk_Subject_Template From [Fk_Subject] Where Fk_Subject_Id=" & Id
	Rs.Open Sqlstr,Conn,1,1
	If Not Rs.Eof Then
		Fk_Subject_Name=Rs("Fk_Subject_Name")
		Fk_Subject_About=Rs("Fk_Subject_About")
		Fk_Subject_Pic=Rs("Fk_Subject_Pic")
		Fk_Subject_Dir=Rs("Fk_Subject_Dir")
		Fk_Subject_Template=Rs("Fk_Subject_Template")
	Else
		Rs.Close
		Call FKFun.ShowErr("专题不存在！",1)
	End If
	Rs.Close
%>
<form id="SubjectEdit" name="SubjectEdit" method="post" target="ajax" action="Subject.asp?Type=5" showStr="专题修改成功！" refreshUrl="Subject.asp?Type=1" boxClose="1">
<div id="title">修改专题</div>
<div id="box">
	<table width="90%" border="1" bordercolor="#CCCCCC" align="center" cellpadding="0" cellspacing="0">
		<tr>
			<td width="24%" height="30" align="right">名称：</td>
			<td width="76%">&nbsp;<input name="Fk_Subject_Name" type="text" class="input" id="Fk_Subject_Name" value="<%=Fk_Subject_Name%>" /><span class="help" title="<p>专题名称，请输入1-50个字符（两个字符为一个汉字）。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">简介：</td>
			<td>&nbsp;<input name="Fk_Subject_About" type="text" class="input" id="Fk_Subject_About" value="<%=Fk_Subject_About%>" /><span class="help" title="<p>对方站点的简介，可留空，请输入0-255个字符（1个汉字为2个字符）。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">图片：</td>
			<td>&nbsp;<input name="Fk_Subject_Pic" type="text" class="input" id="Fk_Subject_Pic" value="<%=Fk_Subject_Pic%>" /> <input type="button" class="picList_btn btnUpload" name="btnLogo" id="btnLogo" value="上传LOGO" callback="2" inputId="Fk_Subject_Pic" fileAction="Upload.asp?immediate=3" /><span class="help" title="<p>专题图片，可留空，请输入0-255个字符，可以输入链接，也可以上传到空间。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">目录：</td>
			<td>&nbsp;<input name="Fk_Subject_Dir" type="text" class="input" id="Fk_Subject_Dir" value="<%=Fk_Subject_Dir%>" /><span class="help" title="<p>专题目录。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">所属类型：</td>
			<td>&nbsp;<select name="Fk_Subject_Template" class="input" id="Fk_Subject_Template">
					<option value="">默认模板</option>
                </select><span class="help" title="<p>选择模板。</p>"></span>
			</td>
		</tr>
	</table>
</div>
<div id="bottom">
	<input type="hidden" name="Id" value="<%=Id%>" />
	<input type="submit" class="button" name="Enter" id="Enter" value="修 改" />
	<input type="button" onclick="dialogClose();" class="button" name="button" id="button" value="关 闭" />
</div>
</form>
<%
End Sub

'==============================
'函 数 名：SubjectEditDo
'作    用：执行修改专题
'==============================
Sub SubjectEditDo()
	Fk_Subject_Name=FKFun.HTMLEncode(Trim(Request.Form("Fk_Subject_Name")))
	Fk_Subject_About=FKFun.HTMLEncode(Trim(Request.Form("Fk_Subject_About")))
	Fk_Subject_Pic=FKFun.HTMLEncode(Trim(Request.Form("Fk_Subject_Pic")))
	Fk_Subject_Dir=Server.URLEncode(FKFun.HTMLEncode(Trim(Request.Form("Fk_Subject_Dir"))))
	Fk_Subject_Template=Trim(Request.Form("Fk_Subject_Template"))
	Id=Trim(Request.Form("Id"))
	Call FKFun.JsonString(Fk_Subject_Name,1,50,0,"请输入专题名称！","专题名称不能大于255个字符！")
	Call FKFun.JsonString(Fk_Subject_About,1,255,2,"请输入专题介绍！","专题介绍不能大于255个字符！")
	Call FKFun.JsonString(Fk_Subject_Pic,1,255,2,"请输入专题图片！","专题图片不能大于255个字符！")
	Call FKFun.JsonString(Fk_Subject_Dir,1,255,2,"请输入专题目录！","专题目录不能大于255个字符！")
	Call FKFun.JsonString(Fk_Subject_Template,1,50,2,"请选择模板！","模板不能大于50个字符！")
	Call FKFun.JsonNum(Id,"系统参数错误，请刷新页面！")
	Sqlstr="Select Fk_Subject_Id,Fk_Subject_Name,Fk_Subject_About,Fk_Subject_Pic,Fk_Subject_Dir,Fk_Subject_Template,Fk_Subject_ToHtml From [Fk_Subject] Where Fk_Subject_Id=" & Id
	Rs.Open Sqlstr,Conn,1,3
	If Not Rs.Eof Then
		Application.Lock()
		Rs("Fk_Subject_Name")=Fk_Subject_Name
		Rs("Fk_Subject_About")=Fk_Subject_About
		Rs("Fk_Subject_Pic")=Fk_Subject_Pic
		Rs("Fk_Subject_Dir")=Fk_Subject_Dir
		Rs("Fk_Subject_Template")=Fk_Subject_Template
		Rs("Fk_Subject_ToHtml")=1
		Rs.Update()
		Application.UnLock()
		Call FKFun.JsonSuccess()
	Else
		Rs.Close
		Call FKFun.JsonError("要修改的专题不存在！")
	End If
	Rs.Close
End Sub

'==============================
'函 数 名：SubjectDelDo
'作    用：执行删除专题
'==============================
Sub SubjectDelDo()
	Id=Trim(Request.QueryString("Id"))
	Call FKFun.ShowNum(Id,"系统参数错误，请刷新页面！")
	Sqlstr="Select Fk_View_Id From [Fk_View] Where Fk_View_Subject Like '%%,"&Id&",%%'"
	Rs.Open Sqlstr,Conn,1,1
	If Not Rs.Eof Then
		Call FKFun.ShowErr("该专题在使用中，无法删除！",2)
	End If
	Rs.Close
	Sqlstr="Select Fk_Subject_Id From [Fk_Subject] Where Fk_Subject_Id=" & Id
	Rs.Open Sqlstr,Conn,1,3
	If Not Rs.Eof Then
		Application.Lock()
		Rs.Delete()
		Application.UnLock()
		Response.Write("ok")
	Else
		Response.Write("要删除的专题不存在！")
	End If
	Rs.Close
End Sub

Call FKFun.PageEnd()
%>
